builder-tool: Convert assistant pages too
authorMatthias Clasen <mclasen@redhat.com>
Thu, 7 Feb 2019 20:34:54 +0000 (15:34 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 8 Feb 2019 05:09:44 +0000 (00:09 -0500)
Do the same transformation for GtkAssistantPage that
we already do for GtkStackPage, to transform GTK 3 .ui
files to GTK 4 ways of doing things.

gtk/tools/gtk-builder-tool-simplify.c

index 69bb02856959fcb33006b8dd6c23882fd94b12a3..759f7c58841e949ced2a97a1e02e73b3e1e40f52 100644 (file)
@@ -576,6 +576,71 @@ rewrite_stack (Element      *element,
   element->children = new_children;
 }
 
+static Element *
+rewrite_assistant_child (Element *child, MyParserData *data)
+{
+  Element *object = NULL;
+  Element *packing = NULL;
+  Element *new_object;
+  Element *prop;
+  GList *l;
+
+  if (!g_str_equal (child->element_name, "child"))
+    return child;
+
+  for (l = child->children; l; l = l->next)
+    {
+      Element *elt = l->data;
+      if (g_str_equal (elt->element_name, "object"))
+        object = elt;
+      else if (g_str_equal (elt->element_name, "packing"))
+        packing = elt;
+    }
+
+  if (!packing)
+    return child;
+
+  new_object = g_new0 (Element, 1);
+  new_object->element_name = g_strdup ("object");
+  new_object->attribute_names = g_new0 (char *, 2);
+  new_object->attribute_names[0] = g_strdup ("class");
+  new_object->attribute_values = g_new0 (char *, 2);
+  new_object->attribute_values[0] = g_strdup ("GtkAssistantPage");
+  new_object->children = packing->children;
+  packing->children = NULL;
+
+  prop = g_new0 (Element, 1);
+  prop->element_name = g_strdup ("property");
+  prop->attribute_names = g_new0 (char *, 2);
+  prop->attribute_names[0] = g_strdup ("name");
+  prop->attribute_values = g_new0 (char *, 2);
+  prop->attribute_values[0] = g_strdup ("child");
+  prop->children = g_list_append (prop->children, object);
+  new_object->children = g_list_append (new_object->children, prop);
+      
+  g_list_free (child->children);
+  child->children = g_list_append (NULL, new_object);
+
+  return child;
+}
+
+static void
+rewrite_assistant (Element      *element,
+                   MyParserData *data)
+{
+  GList *l, *new_children;
+
+  new_children = NULL;
+  for (l = element->children; l; l = l->next)
+    {
+      Element *child = l->data;
+      new_children = g_list_append (new_children, rewrite_assistant_child (child, data));
+    }
+
+  g_list_free (element->children);
+  element->children = new_children;
+}
+
 static gboolean
 simplify_element (Element      *element,
                   MyParserData *data)
@@ -617,6 +682,10 @@ simplify_element (Element      *element,
       if (g_str_equal (element->element_name, "object") &&
           g_str_equal (get_class_name (element), "GtkStack"))
         rewrite_stack (element, data);
+
+      if (g_str_equal (element->element_name, "object") &&
+          g_str_equal (get_class_name (element), "GtkAssistant"))
+        rewrite_assistant (element, data);
           
       if (g_str_equal (element->element_name, "property") &&
           property_has_been_removed (element, data))